#ifndef CLOSEST_VERTEX_SELECTOR_H
#define CLOSEST_VERTEX_SELECTOR_H

#include <map>
#include <set>

#include "SurfaceSelector.h"
#include "Simplex.h"
#include "EdgeIntersection.h"
#include "TetrahedronIntersection.h"


typedef std::map<Simplex,EdgeIntersection*,SimplexLess> EdgeInterMap;
typedef std::map<Tetrahedron*,TetrahedronIntersection*> TetrahedronInterMap;

class ClosestVertexSelector : public SurfaceSelector
{
public:
	~ClosestVertexSelector ();
	ClosestVertexSelector (FiniteElementModel*);

private:
	EdgeInterMap edge_inters_;
	TetrahedronInterMap tet_inters_;
	std::set<TetnodTuple> to_reposition_node_;

	virtual void Visualize (FEMDrawer*)const;

protected:
	virtual void JunkInvalidInformation ();

	virtual void ValidatePointers ()const;
	virtual void UpdateNodes (AllCutComponentsMap const*);
	virtual bool RepositionNode (Node*, Vector3*,Vector3*, LinkArray<Tetrahedron>);

	virtual void RepositionNodes (Array<TetnodTuple>);
	virtual LinkArray<Triangle> SelectSurface ();
	virtual void ClearThisSweep ();
	virtual void NextSweep ();
private:
	void JunkCurrentCut ();

	EdgeIntersection *GetEdgeInter (Simplex const &, bool *clipped);

	TetrahedronIntersection *GetTetrahedronIntersection (Tetrahedron * tet,
		TetrahedronIntersection*);
	void AddSnappedNode (LinkArray<Tetrahedron> cell, Node *center);
};


#endif